﻿using System.Text.RegularExpressions;

namespace WebCrawlerLib.Common
{
    public class BingWallPaperUtility
    {
        public static string GetPictureUrl(string html)
        {
            string url;
            string regex = System.Configuration.ConfigurationManager.AppSettings["BingWallPaperJob_Regex2"];
            string domanRegex = System.Configuration.ConfigurationManager.AppSettings["BingWallPaperJob_Domain"];
            Regex re = new Regex(regex);
            Regex dre = new Regex(domanRegex);
            Match match = re.Match(html);
            Match dmatch = dre.Match(html);
            var split = dmatch.Value.Split('"');
            if (!match.Value.Contains("ts1.tc.mm.bing.net") && split.Length > 1 && split[2].Contains("ts1.tc.mm.bing.net"))
            {
                //url = "http://s.cn.bing.net" + match.Value; //modify 2017-03-03
                //url = "http://cn.bing.com" + match.Value;
                //url = split[1].Substring(1, split[1].Length - 2) + match.Value;
                url = split[2];
            }
            else
                url = match.Value;
            return url;
        }
    }
}
